﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CRM.Component.Business;
using TRPOP.CRM.Component.Common;
using TRPOP.CRM.Component.Model;

namespace TRPOP.CRM.Web
{
    public partial class WorkingLog_save : BaseAdmin
    {
        protected CompanyInfo m_CompanyInfo = new CompanyInfo();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadBase();
            }
        }

        void LoadBase()
        {
            PageBindHelper.BindCompanyCategoryInfo(ddlCompanyCategory);
            PageBindHelper.BindCompanyStatus(ddlCompanyStatus);
            PageBindHelper.BindCompanyGradeInfo(ddlCompanyGrade);
            PageBindHelper.BindCompanySourceInfo(ddlCompanySource);
            PageBindHelper.BindFollowUpCategoryInfo(ddlFollowUpCategory);

            int intCompanyID = RequestHelper.RequestInt("id");
            m_CompanyInfo = CompanyManage.GetCompanyInfo(intCompanyID);
            if (m_CompanyInfo != null)
            {
                ViewState["CompanyInfo"] = m_CompanyInfo;

                ddlCompanyCategory.SelectedValue = m_CompanyInfo.iCompanyCategoryID.ToString();
                ddlCompanyStatus.SelectedValue = m_CompanyInfo.iCompanyStatus.ToString();
                ddlCompanyGrade.SelectedValue = m_CompanyInfo.iCompanyGradeID.ToString();
                ddlCompanySource.SelectedValue = m_CompanyInfo.iCompanySourceID.ToString();
            }
            else
            {
                Alert("客户信息加载失败", "MyRemind_alllist.aspx");
                m_CompanyInfo = new CompanyInfo();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            float fltest = 0;
            if (txtnvcExtention2.Text.IsEmpty() == false && float.TryParse(txtnvcExtention2.Text, out fltest) == false)
            {
                Alert("价格格式输入不正确，请输入小数或整数!");
                return;
            }

            int inttest = 0;
            if (txtnvcExtention3.Text.IsEmpty() == false && int.TryParse(txtnvcExtention3.Text, out inttest) == false)
            {
                Alert("数量格式输入不正确，请输入小数或整数!");
                return;
            }

            if (ViewState["CompanyInfo"] != null)
            {
                m_CompanyInfo = ViewState["CompanyInfo"] as CompanyInfo;

                if (chkResult.Checked)
                {
                    m_CompanyInfo.iEmployeeFollowup = 0;
                    m_CompanyInfo.iCompanyStatus = 2;
                    CompanyManage.SaveCompanyInfo(m_CompanyInfo);
                }

                WorkingLogInfo oWorkingLogInfo = new WorkingLogInfo();

                oWorkingLogInfo.dtCreationTime = DateTime.Now;
                oWorkingLogInfo.iCompanyID = m_CompanyInfo.iCompanyID;
                oWorkingLogInfo.iEmployeeID = base.GetCurrentEmployeeInfo().iEmployeeID;
                oWorkingLogInfo.iFollowUpCategoryID = ddlFollowUpCategory.SelectedValue.ToInt();
                oWorkingLogInfo.nvcDiscription = txtDiscription.Text;
                oWorkingLogInfo.nvcExtention1 = txtnvcExtention1.Text;
                oWorkingLogInfo.nvcExtention2 = txtnvcExtention2.Text;
                oWorkingLogInfo.nvcExtention3 = txtnvcExtention3.Text;

                EmployeeManage.SaveWorkLog(oWorkingLogInfo);

                Alert("跟踪记录保存成功！", "MyRemind_alllist.aspx");
            }
            else
            {
                Alert("客户信息加载失败", "MyRemind_alllist.aspx");
            }
        }
    }
}